package com.zzyl.common.ai;

import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.model.chat.ChatResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class AIModelInvoker {
    private final BaiduAIProperties  baiduAIProperties;
    /**
      * 调用百度AI接口
      * @param Prompt 提示语
     *
     */
    public String chatCompletion(String Prompt) {
        Qianfan qianfan = new Qianfan(baiduAIProperties.getAccessKey(), baiduAIProperties.getSecretKey());
        ChatResponse chatResponse = qianfan.chatCompletion()
                .model(baiduAIProperties.getModel())
                .addMessage("user", Prompt)
                .temperature(0.7)
                .maxOutputTokens(2000)
                .responseFormat("json_object")
                .execute();
         return chatResponse.getResult();
    }
}
